﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Work2
{
    public partial class FrmSearchMate : Form
    {
        public System.Windows.Forms.TextBox txt;
        int flag = 0;
        public FrmSearchMate(System.Windows.Forms.TextBox txt)
        {
            this.txt = txt;
            InitializeComponent();
        }
        DataSet ds = new DataSet();
        DataView dv = null;
        private void FrNewSearch3_Load(object sender, EventArgs e)
        {
            string conStr = @"Data Source=LAPTOP-LER1MVBI\SQLEXPRESS;Initial Catalog=电子族谱系统;uid=sa;pwd=zxcvbnm123";
            SqlConnection conn = new SqlConnection(conStr);
            string assetName = txt.Text.Trim();
            if (assetName == "")
            {
                flag = 1;
                MessageBox.Show("暂无相关数据");

            }
            else
            {
                string sql = "select Umate_id,Umate_name,Umate_birth,User_name from Umate,Users where Umate.[user]=Users.User_id";
                SqlDataAdapter adapter = new SqlDataAdapter(sql, conn);
                adapter.Fill(ds, "电子族谱系统");
                dv = ds.Tables["电子族谱系统"].DefaultView;
                dataGridView1.DataSource = dv;
                dv.RowFilter = string.Format("User_name like '%{0}%'", assetName);
            }
            if (flag == 0 && dv == null)
            {
                MessageBox.Show("暂无相关数据");
            }
        }
    }
}
